package cn.vivi.recyclercomp.fragment;

import cn.vivi.recyclercomp.LastItemMatchParentSpanSizeLookup;
import cn.vivi.recyclercomp.adapter.RecyclerViewBaseAdapter;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.GridLayoutManager.SpanSizeLookup;
import android.support.v7.widget.RecyclerView.LayoutManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;

public abstract class RecyclerGridViewFragment extends RecyclerViewBaseFragment implements
		AdapterView.OnItemClickListener, AdapterView.OnItemLongClickListener {

	private static final String TAG = RecyclerGridViewFragment.class.getSimpleName();
	private int mSpanCount = 2;

	public RecyclerGridViewFragment(int spanCount) {
		mSpanCount = spanCount;
	}


	@Override
	public LayoutManager createLayoutManager() {
		GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), mSpanCount);
		LastItemMatchParentSpanSizeLookup spanSizeLookup = new LastItemMatchParentSpanSizeLookup();
		spanSizeLookup.setAdapter(getAdapter());
		gridLayoutManager.setSpanSizeLookup(spanSizeLookup);
		return gridLayoutManager;
	}


	@Override
	protected void initialize() {
		super.initialize();
		setTriggerLoadItemCount(mSpanCount*3);
	}


}
